{template 'common/header'}
{template 'plateform/nav'}
<ul class="nav nav-tabs">
	<li {if $op == 'category' || $op == 'category_post'}class="active"{/if}><a href="{php echo $this->createWebUrl('ptfarticle', array('op' => 'category'));}">新闻分类</a></li>
	<li {if $op == 'list'}class="active"{/if}><a href="{php echo $this->createWebUrl('ptfarticle', array('op' => 'list'));}">新闻列表</a></li>
	<li {if $op == 'post' && !$id}class="active"{/if}><a href="{php echo $this->createWebUrl('ptfarticle', array('op' => 'post'));}">添加新闻</a></li>
	{if $op == 'post' && $id}<li class="active"><a href="{php echo $this->createWebUrl('ptfarticle', array('op' => 'post', 'id' => $id));}">编辑新闻</a></li>{/if}
</ul>
{if $op == 'list'}
<div class="clearfix">
	<div class="panel panel-info">
		<div class="panel-heading">筛选</div>
		<div class="panel-body">
			<form action="" method="get" class="form-horizontal" role="form">
				<input type="hidden" name="c" value="site">
				<input type="hidden" name="a" value="entry">
				<input type="hidden" name="m" value="we7_wmall">
				<input type="hidden" name="do" value="ptfarticle"/>
				<input type="hidden" name="op" value="list"/>
				<input type="hidden" name="cateid" value="{$_GPC['cateid']}">
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">新闻分类</label>
					<div class="col-sm-8 col-lg-9 col-xs-12">
						<div class="btn-group">
							<a href="{php echo filter_url('cateid:0');}" class="btn {if $_GPC['cateid'] == 0}btn-primary{else}btn-default{/if}">不限</a>
							{loop $categorys $category}
							<a href="{php echo filter_url('cateid:' . $category['id']);}" class="btn {if $_GPC['cateid'] == $category['id']}btn-primary{else}btn-default{/if}">{$category['title']}</a>
							{/loop}
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">标题</label>
					<div class="col-sm-8 col-lg-3 col-xs-12">
						<input class="form-control" name="title" id="" type="text" value="{$_GPC['title']}">
					</div>
					<div class="pull-left col-xs-12 col-sm-2 col-lg-2">
						<button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<form action="{php echo $this->createWebUrl('ptfarticle', array('op' => 'batch_post'))}" method="post" class="form-horizontal" role="form">
		<div class="panel panel-default">
			<div class="panel-body table-responsive">
				<table class="table table-hover">
					<thead>
					<tr>
						<th width="80">排序</th>
						<th width="100">阅读次数</th>
						<th width="300">标题</th>
						<th>所属分类</th>
						<th>是否显示</th>
						<th>添加时间</th>
						<th class="text-right">操作</th>
					</tr>
					</thead>
					<tbody>
					{loop $articles $article}
					<input type="hidden" name="ids[]" value="{$article['id']}" />
					<tr>
						<td>
							<input type="text" class="form-control" name="displayorder[]" value="{$article['displayorder']}"/>
						</td>
						<td>
							<input type="text" class="form-control" name="click[]" value="{$article['click']}"/>
						</td>
						<td>
							<input type="text" class="form-control" name="title[]" value="{$article['title']}"/>
						</td>
						<td>{$categorys[$article['cateid']]['title']}</td>
						<td>
							<input type="checkbox" value="{$article['status']}" name="status[]" data-id="{$article['id']}" {if $article['status'] == 1}checked{/if}>
						</td>
						<td>{php echo date('Y-m-d H:i', $article['createtime']);}</td>
						<td class="text-right">
							<a href="{php echo $this->createWebUrl('ptfarticle', array('op' => 'post', 'id' => $article['id']))}" class="btn btn-default">编辑</a>
							<a href="{php echo $this->createWebUrl('ptfarticle', array('op' => 'del', 'id' => $article['id']))}" onclick="if(!confirm('确定删除吗')) return false;" class="btn btn-default">删除</a>
						</td>
					</tr>
					{/loop}
					</tbody>
				</table>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-8 col-lg-9 col-xs-12">
				<input type="submit" class="btn btn-primary" name="submit" value="提交" />
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
		{$pager}
	</form>
</div>
{elseif $op == 'post'}
<div class="clearfix">
	<form action="" method="post" class="form-horizontal" role="form" id="form1">
		<input type="hidden" name="id" value="{$article['id']}"/>
		<div class="panel panel-default">
			<div class="panel-heading">编辑新闻</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">新闻标题</label>
					<div class="col-sm-8 col-lg-9 col-xs-12">
						<input type="text" class="form-control" name="title" value="{$article['title']}" placeholder="新闻标题"/>
						<div class="help-block">请填写新闻标题</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">新闻分类</label>
					<div class="col-sm-8 col-lg-9 col-xs-12">
						<select name="cateid" id="cateid" class="form-control">
							<option value="">==请选择新闻分类==</option>
							{loop $categorys $category}
							<option value="{$category['id']}" {if $article['cateid'] == $category['id']}selected{/if}>{$category['title']}</option>
							{/loop}
						</select>
						<div class="help-block">还没有分类，点我 <a href="{php echo $this->createWebUrl('ptfarticle', array('op' => 'category_post'))}" target="_blank"><i class="fa fa-plus-circle"></i> 添加分类</a></div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">缩略图</label>
					<div class="col-sm-8 col-lg-9 col-xs-12">
						{php echo tpl_form_field_image('thumb', $article['thumb'], '');}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">内容</label>
					<div class="col-sm-8 col-lg-9 col-xs-12">
						{php echo tpl_ueditor('content', $article['content']);}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">阅读次数</label>
					<div class="col-sm-8 col-lg-9 col-xs-12">
						<input type="text" class="form-control" name="click" value="{$article['click']}" placeholder="阅读次数"/>
						<div class="help-block">默认为0。您可以设置一个初始值,阅读次数会在该初始值上增加。</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">排序</label>
					<div class="col-sm-8 col-lg-9 col-xs-12">
						<input type="text" class="form-control" name="displayorder" value="{$article['displayorder']}" placeholder="阅读次数"/>
						<div class="help-block">数字越大，越靠前。</div>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-8 col-lg-9 col-xs-12">
				<input type="submit" class="btn btn-primary" name="submit" value="提交" />
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
	</form>
</div>
{/if}
<script>
	require(['bootstrap.switch'], function($){
		$('#form1').submit(function(){
			if(!$.trim($(':text[name="title"]').val())) {
				util.message('请填写新闻标题', '', 'error');
				return false;
			}
			if(!$.trim($('#cateid').val())) {
				util.message('请选择新闻分类', '', 'error');
				return false;
			}
			if(!$.trim($('textarea[name="content"]').val())) {
				util.message('请填写新闻内容', '', 'error');
				return false;
			}
			return true;
		});
		$(':checkbox[name="status[]"]').bootstrapSwitch();
		$(':checkbox[name="status[]"]').on('switchChange.bootstrapSwitch', function(e, state){
			var status = this.checked ? 1 : 0;
			var id = $(this).data('id');
			$.post(location.href, {status: status, id: id}, function(resp){
				setTimeout(function(){
					location.reload();
				}, 500)
			});
		});
	});
</script>
{template 'common'}
{template 'common/footer'}
